package com.wugui.datax.admin.dto;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class ColumnTypeDto implements Serializable {

    private String mysqlColumnType;

    private String oracleColumnType;

    public static Map<String, String> defaultColumnTypeMap() {
        Map<String, String> map = new HashMap<>();
        map.put("int", "NUMBER");
        map.put("bigint", "NUMBER");
        map.put("varchar", "VARCHAR2");
        map.put("datetime", "VARCHAR2(60)");
        map.put("date", "VARCHAR2(60)");
        map.put("time", "VARCHAR2(60)");
        map.put("year", "VARCHAR2(60)");
        map.put("timestamp", "VARCHAR2(60)");
        map.put("decimal", "VARCHAR2(60)");
        map.put("double", "VARCHAR2(60)");
        map.put("float", "VARCHAR2(60)");
        //map.put("tinyint", "NUMBER");
        map.put("text", "CLOB");
        map.put("longtext", "CLOB");
        map.put("longblob", "CLOB");
        map.put("mediumblob", "CLOB");
        map.put("mediumtext", "CLOB");
        map.put("tinyblob", "CLOB");
        map.put("tinytext", "CLOB");
        map.put("blob", "CLOB");
        return map;
    }
    public static Map<String, String> defaultDataTypeMap() {
        Map<String, String> map = new HashMap<>();
        map.put("int", "NUMBER");
        map.put("bigint", "NUMBER");
        map.put("varchar", "VARCHAR2");
        map.put("datetime", "VARCHAR2");
        map.put("date", "VARCHAR2");
        map.put("time", "VARCHAR2");
        map.put("year", "VARCHAR2");
        map.put("timestamp", "VARCHAR2");
        map.put("decimal", "VARCHAR2");
        map.put("float", "VARCHAR2");
        map.put("double", "VARCHAR2");
        //map.put("tinyint", "NUMBER");
        map.put("text", "CLOB");
        map.put("longblob", "CLOB");
        map.put("longtext", "CLOB");
        map.put("mediumblob", "CLOB");
        map.put("tinyblob", "CLOB");
        map.put("mediumtext", "CLOB");
        map.put("tinytext", "CLOB");
        map.put("blob", "CLOB");
        return map;
    }

    public static String convertColumnType(String columnType, Map<String, String> columnTypeMap) {
        String columnTypeStr = columnType.toLowerCase();
        String mysqlColumnType = "";
        String oracleColumnType = "";
        if (columnTypeStr.contains("(")) {
            mysqlColumnType = columnTypeStr.substring(0, columnTypeStr.indexOf("("));
        } else {
            mysqlColumnType = columnTypeStr;
        }
        oracleColumnType = columnTypeMap.get(mysqlColumnType) == null ? "VARCHAR2(100)" : columnTypeMap.get(mysqlColumnType);
        return columnTypeStr.replace(mysqlColumnType, oracleColumnType);
    }

    public static String convertDataType(String columnType) {
        String mysqlColumnType =columnType.toLowerCase();
        Map<String, String> columnTypeMap = ColumnTypeDto.defaultDataTypeMap();
        String oracleColumnType = columnTypeMap.get(mysqlColumnType) == null ? "VARCHAR2" : columnTypeMap.get(mysqlColumnType);
        return mysqlColumnType.replace(mysqlColumnType, oracleColumnType);
    }

    public String getMysqlColumnType() {
        return mysqlColumnType;
    }

    public void setMysqlColumnType(String mysqlColumnType) {
        this.mysqlColumnType = mysqlColumnType;
    }

    public String getOracleColumnType() {
        return oracleColumnType;
    }

    public void setOracleColumnType(String oracleColumnType) {
        this.oracleColumnType = oracleColumnType;
    }
}
